package core.bmp.worker;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

import core.bmp.Bmp;

public class FlipWoker {

	public static void flipImageHorizontal(File src, File dst) {

		try {
			BufferedImage bufferedimage = ImageIO.read(src);

			int w = bufferedimage.getWidth();
			int h = bufferedimage.getHeight();

			BufferedImage img;
			Graphics2D graphics2d;
			graphics2d = (img = new BufferedImage(w, h, bufferedimage.getColorModel().getTransparency()))
					.createGraphics();

			graphics2d.drawImage(bufferedimage, 0, 0, w, h, w, 0, 0, h, null);
			graphics2d.dispose();
			ImageIO.write(img, "bmp", dst);

		} catch (Exception e) {

		}

	}

	public static void flipImageVertical(File src, File dst) {

		try {
			BufferedImage bufferedimage = ImageIO.read(src);

			int w = bufferedimage.getWidth();
			int h = bufferedimage.getHeight();

			BufferedImage img;
			Graphics2D graphics2d;
			graphics2d = (img = new BufferedImage(w, h, bufferedimage.getColorModel().getTransparency()))
					.createGraphics();

			graphics2d.drawImage(bufferedimage, 0, 0, w, h, 0, h, w, 0, null);
			graphics2d.dispose();
			ImageIO.write(img, "BMP", dst);

		} catch (Exception e) {

		}

	}

	public static void main(String[] args) {
		flipImageHorizontal(Bmp.BMP_LENA, new File(Bmp.DIR_FILE, FlipWoker.class.getSimpleName() + "_hor_.bmp"));
		flipImageVertical(Bmp.BMP_LENA, new File(Bmp.DIR_FILE, FlipWoker.class.getSimpleName() + "_ver_.bmp"));
	}
}
